<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>修改岗位类型</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../css/oksub.css">
</head>
<body>
<div class="ok-body">
    <!--form表单-->
    <form class="layui-form ok-form" lay-filter="filter">
        <div class="layui-form-item">
            <label class="layui-form-label">岗位类型id</label>
            <div class="layui-input-block">
                <input readonly unselectable="on" type="number" name="typeid"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">岗位名称</label>
            <div class="layui-input-block">
                <input type="text" name="typename" placeholder="请输入岗位名称" autocomplete="off" class="layui-input"
                       lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="edit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                <button class="layui-btn layui-btn-warm" id="reloadData" lay-filter="reloadData">重新获取</button>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <legend style="color: #ff0000;font-size: 10px">数据可能获取失败请重新获取或更换浏览器内核(部分浏览器极速模式失败概率高)</legend>
            </div>
        </div>
    </form>
</div>
<!--js逻辑-->
<script src="../../lib/layui/layui.js"></script>
<script src="../../../../js/model.js"></script>
<script>
    let initData;

    //其他页面传过来的数据
    function initForm(data) {
        let jsonString = JSON.stringify(data);
        console.log(jsonString)
        initData = JSON.parse(jsonString);
        console.log(initData)
    }

    layui.use(["form", "okUtils", "okLayer", "jquery"], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let okLayer = layui.okLayer;

        form.val("filter", initData);
        // 获取contentText
        const ctx = function () {
            let pathName = document.location.pathname;
            let index = pathName.substr(1).indexOf("/");
            let result = pathName.substr(0, index + 1);
            return result;
        }();

        form.on("submit(edit)", function (data) {
            var initData = data.field;
            var jobtype = new JobType(initData.typeid, initData.typename);
            $.ajax({
                url: ctx + '/ygssecs/updatejobtype',
                type: 'POST',
                data: {"jobtypejson": JSON.stringify(jobtype)},
                dataType: 'json',
                error: function () {
                    okLayer.redCrossMsg("服务器错误")
                },
                success: function (data) {
                    if (data.code == 200) {
                        // 业务正常
                        okLayer.greenTickMsg("编辑成功", function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                        });
                    } else {
                        // 业务异常
                        okLayer.yellowSighMsg(data.msg)
                    }
                }
            });
            return false;
        });

        form.on("submit(reloadData)", function (data) {
            form.val("filter", initData);
        });
    });
</script>
</body>
</html>
